/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import javax.swing.JOptionPane;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Anderson
 */
public class DaoSessionManager {
    
    public static Session getSessaoAtual() {
        return HibernateUtil.getSessionfactory().getCurrentSession();
    }
    
    public static Transaction getTransacaoAberta() {
        return getSessaoAtual().beginTransaction();
    }
    
    public static void commit() {
        try {
            getTransacaoAberta().commit();
        } catch (Exception e) {
            getTransacaoAberta().rollback();
            JOptionPane.showMessageDialog(null, "Não foi possível salvar os dados.");
        }

    }
}
